var reporturl="http://www.w3schools.com/";
// JavaScript Document
$(document).ready(function(e) {
	$("#spanDatetimepicker1").click(function() {
		document.getElementById("datetimepicker1").focus();
	});
	$("#spanDatetimepicker2").click(function() {
		document.getElementById("datetimepicker2").focus();
	});
	
	// เพื่อให้ footer ลงมาอยู่ด้านล่าง
	var mainHeight=$(document).outerHeight();
	$('#right-side,#side-menu-bar').css('min-height',mainHeight-85);
	
	$('#hide-button').on('click',function() {
		if ($('#box-body').is(':visible')) {
			$(this).html('<i class="fa fa-chevron-circle-down"></i>');
		}else {
			$(this).html('<i class="fa fa-chevron-circle-up"></i>');
		}
		$('#box-body').slideToggle();
	});
	$('.table-action > i').tooltip();
	
	$('#closeflim').on('click',function(){
		$('.flim-white').fadeOut();
	});
	
	$('#openflim').on('click',function(){
		$('.flim-white').fadeIn('slow',function(){
			var body = $("html, body");
			body.animate({scrollTop:0}, '500', 'swing', function() { 
			   
			});
		});
		
	});
	
	$('.change-bg').on('click',function() {
		var $id=$(this).attr('id');	
		
		$('.change-bg').each(function(index, element) {
			var $rid=$(this).attr('id');
			$('#right-side').removeClass($rid);
			$('.form-wizard-box').removeClass($rid);
		});
		$('#right-side').addClass($id);	
		$('.form-wizard-box').addClass($id);
	
	});
	
	$('.page-sidebar-menu > li > a').on('click',function() {
		var parent=$(this).parent();
		var $this=$(this);
		parent.next().children('a').addClass('add-border-top');
		//if (!$(this).hasClass('active')){
		if (!parent.hasClass('active')){
		$('.sub-menu').slideUp('fast',function() {
				$(this).prev('a').removeClass('add-border-top');
				//$('.page-sidebar-menu > li > a').removeClass('active');
				$('.page-sidebar-menu > li').removeClass('active');
				$('.page-sidebar-menu > li > a >span').removeClass('open');
				//$(this).children('li').children('a').removeClass('active'); 
				$(this).children('li').removeClass('active'); 
				$(this).children('li').children('a').children('span.arrow').removeClass('open');
				$(this).children('li').children('.sub-menu').hide();		
		});
		}
		parent.children('ul').slideToggle('fast',function() {
			if (parent.children('ul').is(':visible')) {
				//$this.addClass('active');
				parent.addClass('active');
				$this.children('span').addClass('open');
			}else {
				parent.next().children('a').removeClass('add-border-top');
				//$this.removeClass('active');
				
				parent.removeClass('active');
				$this.children('span').removeClass('open');
				parent.children('.sub-menu').hide();
				//parent.children('.sub-menu').children('li').children('a').removeClass('active'); 
				parent.children('.sub-menu').children('li').removeClass('active'); 
				parent.children('.sub-menu').children('li').children('a').children('span.arrow').removeClass('open');
				parent.children('.sub-menu').children('li').children('.sub-menu').hide();
			}
		});
	});
	
	$('.sub-menu > li > a').on('click',function() {
		var parent=$(this).parent();
		var $this=$(this);
		parent.children('ul').slideToggle('fast',function() {
			if (parent.children('ul').is(':visible')){
				//$this.addClass('active');
				parent.addClass('active');
				$this.children('span').addClass('open');
			}else{
				//$this.removeClass('active');
				parent.removeClass('active');
				$this.children('span').removeClass('open');
			}
		});
	});
	
	$('.step-link').on('click',function() {
		var boxID=$(this).data('link');
		$('.form-wizard-box').removeClass('active');
		$(this).children().addClass('active');
		// ------- add
		$('.step-link').removeClass('active');
		$(this).addClass('active');
		// ------- end add
		$('.form-step').fadeOut('slow',function() {
			setTimeout(function() {
				$('#'+boxID).fadeIn('slow');
			},300);
		});
	});

	if($("#url_address").val() != 'NULL'){
		$("#url_address").val(location.href);
	}
	
	if($("#agent_browser").val() != 'NULL'){
		$("#agent_browser").val(getBrowserName());
	}

});

function getBrowserName() {
	var objAgent = navigator.userAgent; 
	var objbrowserName = navigator.appName; 
	var objfullVersion = ''+parseFloat(navigator.appVersion); 
	var objBrMajorVersion = parseInt(navigator.appVersion,10); 
	var objOffsetName,objOffsetVersion,ix; 
	// In Chrome 
	if ((objOffsetVersion=objAgent.indexOf("Chrome"))!=-1) { 
		objbrowserName = "Chrome"; 
		objfullVersion = objAgent.substring(objOffsetVersion+7); 
	} // In Microsoft internet explorer 
	else if ((objOffsetVersion=objAgent.indexOf("MSIE"))!=-1) { 
		objbrowserName = "Microsoft Internet Explorer"; 
		objfullVersion = objAgent.substring(objOffsetVersion+5); 
	} // In Firefox
	else if ((objOffsetVersion=objAgent.indexOf("Firefox"))!=-1) { 
		objbrowserName = "Firefox"; 
	} // In Safari 
	else if ((objOffsetVersion=objAgent.indexOf("Safari"))!=-1) { 
		objbrowserName = "Safari"; 
		objfullVersion = objAgent.substring(objOffsetVersion+7); 
		if ((objOffsetVersion=objAgent.indexOf("Version"))!=-1) 
			objfullVersion = objAgent.substring(objOffsetVersion+8); 
	} // For other browser "name/version" is at the end of userAgent 
	else if ( (objOffsetName=objAgent.lastIndexOf(' ')+1) < (objOffsetVersion=objAgent.lastIndexOf('/')) ) { 
		objbrowserName = objAgent.substring(objOffsetName,objOffsetVersion); 
		objfullVersion = objAgent.substring(objOffsetVersion+1); 
		if (objbrowserName.toLowerCase()==objbrowserName.toUpperCase()) { 
			objbrowserName = navigator.appName; 
		} 
	} 
	// trimming the fullVersion string at semicolon/space if present 
	if ((ix=objfullVersion.indexOf(";"))!=-1) 
		objfullVersion=objfullVersion.substring(0,ix); 
	if ((ix=objfullVersion.indexOf(" "))!=-1) 
		objfullVersion=objfullVersion.substring(0,ix); 
	objBrMajorVersion = parseInt(''+objfullVersion,10); 
	if (isNaN(objBrMajorVersion)) { 
		objfullVersion = ''+parseFloat(navigator.appVersion); 
	objBrMajorVersion = parseInt(navigator.appVersion,10); } 
	/*
	'Browser name = '+objbrowserName+'<br>' 
	+'Full version = '+objfullVersion+'<br>' 
	+'Major version = '+objBrMajorVersion+'<br>' 
	+'navigator.appName = '+navigator.appName+'<br>' 
	+'navigator.userAgent = '+navigator.userAgent+'<br>'
	*/
	return 'Browser name: ' + objbrowserName + ', Version: ' + objfullVersion;
}


